package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPageVo;
import com.zzyl.vo.NursingPlanVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/nursing/plan")
@Slf4j
public class NursingPlanController extends BaseController{
    @Autowired
    private NursingPlanService nursingPlanService;

    /**
     * 新增护理计划
     */
    @PostMapping
    @ApiOperation("新增护理计划")
    public ResponseResult addNursingPlan(@RequestBody NursingPlanDto nursingPlanDto) {
        log.info("新增护理计划");
        // 调用业务层方法来新增护理计划
        nursingPlanService.addNursingPlan(nursingPlanDto);
        return ResponseResult.success();
    }

    /**
     * 条件分页查询
     */
    @GetMapping("/search")
    @ApiOperation("分页查询护理计划")
    public ResponseResult<PageResponse<NursingPlanVo>> getPage(
            @ApiParam(value = "护理计划名称") String name, @ApiParam(value = "页码") Integer pageNum,
            @ApiParam(value = "每页大小") Integer pageSize, @ApiParam(value = "护理计划状态") Integer status
    ) {
        log.info("分页查询护理计划");
        // 调用业务层查询所有的护理计划并返回
        PageResponse<NursingPlanVo> pageNursingPlan = nursingPlanService.getPage(name, pageNum, pageSize, status);
        return ResponseResult.success(pageNursingPlan);
    }

    /**
     * 查询所有的护理计划
     * @return
     */
    @GetMapping
    public ResponseResult getAllNursingPlan(){
        List<NursingPlanVo> list = nursingPlanService.getAllNursingPlan();
        return success(list);
    }
    /**
     * 根据ID回显信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseResult<NursingPlanVo> getInfoByID(@PathVariable Integer id){
        NursingPlanVo nursingPlanVo = nursingPlanService.getInfoByID(id);
        log.info("打印回显的信息{}",nursingPlanVo);
        return success(nursingPlanVo);
    }

    /**
     * 编辑护理计划信息
     * @param nursingPlanDto
     * @return
     */
    @PutMapping("/{id}")
    public ResponseResult updatePlanInfo(@RequestBody NursingPlanDto nursingPlanDto){
        log.info("接收到的信息为{}",nursingPlanDto);
        nursingPlanService.updatePlanInfo(nursingPlanDto);
        return success();
    }

    /**
     * 根据id删除护理计划
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public ResponseResult deletePlanById(@PathVariable Integer id){
        nursingPlanService.deletePlanById(id);
        return success();
    }

    /**
     * 根据ID更改计划状态
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    public ResponseResult updateStatus(@PathVariable Integer id,@PathVariable Integer status){
        log.info("获取信息id:{},status:{}",id,status);
        nursingPlanService.updateStatus(id,status);
        return success();
    }

}
